import org.apache.hadoop.io.Text;

import java.util.ArrayList;
import java.util.Arrays;

public class PayrollDateFomat {
    private String month;
    private String year;
    private String day;

    public Text PingJie(Text T) {
//1.切割文本行
        String[] sp = T.toString().split(",");
//2.获取字符串日期并进行切割
        String date = sp[4];
        String[] split = date.split("-");
//3.获取day
        day = split[0];
//4.替换“月”字
        String s = split[1];
        String m = s.replace("月", "");
//5.拼接month
        int i = Integer.parseInt(m);
        if (i < 10) {
            month = "0" + i;
        } else {
            month =Integer.toString(i) ;
        }
//6.拼接year
        year = split[2];
        int i1 = Integer.parseInt(year);
        if (2000 + i1 < 2020 & 2000 + i1 >= 2000) {
            Integer i2 = 2000 + i1;
            year = Integer.toString(i2);
        } else {
            Integer i3 = 1900 + i1;
            year = Integer.toString(i3);
        }
//7.拼接年月日
        //7.1数组转换为Arraylist集合，替换集合中日期
        ArrayList<String> array = new ArrayList<String>(Arrays.asList(sp));
        StringBuilder sb = new StringBuilder();
        sb.append(year).append("-").append(month).append("-").append(day);
        array.set(4, sb.toString());
        //7.3遍历集合中的元素并添加到新的sb1中
        StringBuilder sb1 = new StringBuilder();
        for (String s1 : array) {
            sb1.append(s1 + ",");
        }
        //返回最终结果
        return new Text(sb1.toString());
    }
}
